package com.jie.deletefile.DialogGestures;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.jie.deletefile.R;

/**
 * Created by Administrator on 2016/11/21 0021.
 */
public class GesturesDialog extends Dialog implements  GestureGroup.OnGestureLockViewListener {

    private final String TAG = "dialog";
    private OnGesturesListener gesturesListener;
    private TextView tv_dialog;
    private GestureGroup dialog_ges;
    private TextView tv_forget_ges;
    private String tv_dialog_text;
    private String tv_forget_test;


    public GesturesDialog(Context context, OnGesturesListener gesturesListener) {
        this(context, R.style.customdialog, gesturesListener);
    }

    public GesturesDialog(Context context, int themeResId, OnGesturesListener gesturesListener) {
        super(context, themeResId);
        this.gesturesListener = gesturesListener;
    }

    /**
     * 重写手势按钮的监听
     * @param cId
     */

    //被选中的编号
    @Override
    public void onBlockSelected(int cId) {
        gesturesListener.onBlockSelected(cId);
    }

    /**
     *
     * @param matched 手势密码是否匹配
     * @param mTryTimes 获取尝试的次数
     */
    @Override
    public void onGestureEvent(boolean matched, int mTryTimes) {
        gesturesListener.onGestureEvent(matched,mTryTimes);
    }


    /**
     * 是否超过密码次数
     */
    @Override
    public void onUnmatchedExceedBoundary() {
        gesturesListener.onUnmatchedExceedBondary();

    }

    /**
     * dialog监听
     */
    public interface OnGesturesListener {
        void onBlockSelected(int ID);

        void onGestureEvent(boolean match,int trytimes);

        void onUnmatchedExceedBondary();

        void onTvForgrtClickListener();
    }


    /**
     * oncreate 在dialog执行show()方法之后执行
     * @param savedInstanceState
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.e(TAG, "onCreate: " );
        View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_gestures, null);
        tv_dialog = (TextView) view.findViewById(R.id.tv_dialog);
        dialog_ges = (GestureGroup) view.findViewById(R.id.dialog_ges);
        tv_forget_ges = (TextView) view.findViewById(R.id.tv_forget_ges);
        setContentView(view);
        dialog_ges.setOnGestureLockViewListener(this);

        tv_forget_ges.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gesturesListener.onTvForgrtClickListener();
            }
        });
    }

    /**
     *
     * @param tv_dialog_text 设置提示textview显示内容
     */
    public void setTv_dialog_text(String tv_dialog_text) {
        this.tv_dialog_text = tv_dialog_text;
        tv_dialog.setText(tv_dialog_text);

    }

    /**
     * 忘记密码
     * @param tv_forget_test
     */
    public void setTv_forget_test(String tv_forget_test) {
        this.tv_forget_test = tv_forget_test;
        tv_forget_ges.setText(tv_forget_test);

    }

    /**
     * 得到dialog中的手势按钮，实现手势按钮中的方法
     * @return
     */
    public GestureGroup getDialog_ges() {
        return dialog_ges;
    }
}
